package com.lagou;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class SortReducer extends Reducer<SortBean,NullWritable, SortBean,NullWritable> {
    Integer i = 1;
    SortBean bean = new SortBean();
    @Override
    protected void reduce(SortBean key, Iterable<NullWritable> values, Context context) throws IOException, InterruptedException {
        //遍历map输出的kv值
        for (NullWritable value : values) {
            //把map传入的key中的num赋给bean的num
            bean.setNum(key.getNum());
            //从1开始排序
            bean.setId(i++);
            //输出
            context.write(bean,NullWritable.get());
        }
    }

}
